package com.mistyrain.service.impl;

import com.mistyrain.entity.Menu;
import com.mistyrain.entity.MenuVO;
import com.mistyrain.feign.MenuFeign;
import com.mistyrain.feign.OrderFeign;
import com.mistyrain.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuFeign menuFeign;
    @Autowired
    private OrderFeign orderFeign;
    @Override
    public MenuVO findAll(int page, int limit) {
        return menuFeign.findAll(page, limit);
    }

    @Override
    public String prepareSave(Model model) {
        model.addAttribute("list",menuFeign.findAll());
        return "menu_add";
    }

    @Override
    public String save(Menu menu) {
        menuFeign.save(menu);
        return "redirect:/account/redirect/menu_manage";
    }

    @Override
    public String findById(long id, Model model) {
        model.addAttribute("list",menuFeign.findAll());
        model.addAttribute("menu",menuFeign.findById(id));
        return "menu_update";
    }

    @Override
    public String update(Menu menu) {
        menuFeign.update(menu);
        return "redirect:/account/redirect/menu_manage";
    }

    @Override
    public String deleteById(long id) {
        orderFeign.deleteByMid(id);
        menuFeign.deleteById(id);
        return "redirect:/account/redirect/menu_manage";
    }
}
